package cn.jiahua.service;

import cn.jiahua.pojo.User;
import junit.framework.TestCase;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;
import java.util.List;

public class TestUserServiceImpl extends TestCase {


    public void testUserService(){
        //1.启动spring容器
        ApplicationContext applicationContext =new ClassPathXmlApplicationContext("ApplicationContext.xml");
        UserService userService = (UserService) applicationContext.getBean("userServiceImpl");
        List<User> userListByPage = userService.getUserListByPage(1, 5, null, null);
        for (int i = 0; i < userListByPage.size(); i++) {
            System.out.println(userListByPage.get(i).toString());
        }

    }


    public void testUserService2(){
        //1.启动spring容器
        ApplicationContext applicationContext =new ClassPathXmlApplicationContext("ApplicationContext.xml");
        UserService userService = (UserService) applicationContext.getBean("userServiceImpl");
        User user= new User();
        user.setUserName("小六");
        user.setUserCode("xiaoliu");
        user.setUserPassword("123456");
        int i = userService.addUser(user);
        if(i>0){
            System.out.println("添加数据成功");
        }
    }

    public void testUserService3(){
        //1.启动spring容器
        ApplicationContext applicationContext =new ClassPathXmlApplicationContext("ApplicationContext.xml");
        DataSource dataSource= (DataSource) applicationContext.getBean("dataSource");
        DataSource dataSource2= (DataSource) applicationContext.getBean("dataSource");
        System.out.println(dataSource==dataSource2);

    }

    public void testUserService4() {
        //1.启动spring容器
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        UserService userService = (UserService) applicationContext.getBean("userServiceImpl");
        UserService userService2 = (UserService) applicationContext.getBean("userServiceImpl");
        System.out.println(userService==userService2);
    }

    public void testUserService5() {
        //1.启动spring容器
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        DataSourceTransactionManager tx=(DataSourceTransactionManager)applicationContext.getBean("txManager");

    }
}

